package com.happy.cat.project.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.happy.cat.project.system.mapper.UserApplyWithdrawMapper;
import com.happy.cat.project.system.domain.UserApplyWithdraw;
import com.happy.cat.project.system.service.IUserApplyWithdrawService;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * 用户提现申请Service业务层处理
 *
 * @author verne
 * @date 2020-08-29
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class UserApplyWithdrawServiceImpl extends ServiceImpl<UserApplyWithdrawMapper, UserApplyWithdraw> implements IUserApplyWithdrawService {

    @Override
    public Integer countsToAccount(String accountName) {
        return this.lambdaQuery().eq(UserApplyWithdraw::getAccountName, accountName).eq(UserApplyWithdraw::getStatus, 1).count();
    }

    @Override
    public Double sumToAmount(String accountName) {
        QueryWrapper<UserApplyWithdraw> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("COALESCE(sum(take_money), 0) as sumMoney");
        queryWrapper.eq("account_name", accountName);
        queryWrapper.eq("status", 1);
        Map<String, Object> map = this.getMap(queryWrapper);
        return Double.parseDouble(map.get("sumMoney").toString());
    }
}
